package activity.video;

import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.media.MediaMetadataRetriever;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hichip.campro.R;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import activity.FishEye.FishEyePlaybackLocalActivity;
import activity.LocalFile.LocalFileActivity;
import activity.LocalFile.LocalFileActivity2;
import activity.WallMounted.WallMountedPlayLocalActivity;
import activity.video.adapter.VideoInfoAdapter;
import activity.video.utils.SizeComparator;
import activity.video.utils.TimeComparator;
import base.HiFragment;
import bean.MyCamera;
import bean.VideoInfo;
import butterknife.BindView;
import butterknife.ButterKnife;
import common.HiDataValue;
import custom.dialog.NiftyDialogBuilder;
import utils.HiToast;
import utils.HiTools;
import utils.SharePreUtils;
/**
 * 本地录像  Fragment
 * Created by lt on 2018\2\27 0027.
 */
public class VideoLocalFragment extends HiFragment implements AdapterView.OnItemClickListener, View.OnClickListener {
    private View layoutView;
    private LocalFileActivity2 act;
    private MyCamera myCamera;
    public VideoInfoAdapter adapter;
    private String absolutePath;
    private List<VideoInfo> video_list = new ArrayList<VideoInfo>();
    public static final String FILE_PATH = "file_path";
    private int mSelectMode_1;//0 所有视频     1 本地录制    2远程下载
    private int mSelectMode_2;//0 时间降序    1 时间升序    2文件大小降序  3文件大小升序
    public List<VideoInfo> delete_video_list = new ArrayList<>();
    @BindView(R.id.list_video_local) ListView list_video_local;
    @BindView(R.id.tv_edit) TextView tv_edit;
    @BindView(R.id.ll_anim) LinearLayout ll_anim;
    @BindView(R.id.ll_category) LinearLayout ll_category; //视频分类
    @BindView(R.id.tv_category) TextView tv_category;
    @BindView(R.id.iv_category) ImageView iv_category;
    @BindView(R.id.ll_time) LinearLayout ll_time;//时间
    @BindView(R.id.tv_time_sort) TextView tv_time_sort;
    @BindView(R.id.iv_time) ImageView iv_time;
    private GotoBroadcastReceiver receiver;

    @BindView(R.id.ll_content) LinearLayout ll_content;
    @BindView(R.id.rl_noting) RelativeLayout rl_noting;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        layoutView = inflater.inflate(R.layout.fragment_video_local, null);
        ButterKnife.bind(this, layoutView);
        initViewAndData();
        setListeners();
        initDataAndView();
        registerComponent();
        return layoutView;
    }


    private void registerComponent() {
        receiver = new GotoBroadcastReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("intent_goto");
        getActivity().registerReceiver(receiver, filter);
    }

    private class GotoBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("intent_goto")) {
                //准备数据源
                loadData();
                Collections.sort(video_list, new TimeComparator());
                adapter = new VideoInfoAdapter(getActivity(), video_list, myCamera);
                list_video_local.setAdapter(adapter);
            }
        }
    }

    private void initDataAndView() {
        //准备数据源
        loadData();
        if(video_list.size()<1){
            ll_content.setVisibility(View.GONE);
            rl_noting.setVisibility(View.VISIBLE);
        }
        Collections.sort(video_list, new TimeComparator());
        adapter = new VideoInfoAdapter(getActivity(), video_list, myCamera);
        list_video_local.setAdapter(adapter);
    }

    private void initViewAndData() {
        act = (LocalFileActivity2) getActivity();
        this.myCamera = act.getmMyCamera();
    }

//    @Override
//    public void setUserVisibleHint(boolean isVisibleToUser) {
//        super.setUserVisibleHint(isVisibleToUser);
//        if (isVisibleToUser) {
//            //准备数据源
//            loadData();
//            Collections.sort(video_list,new TimeComparator());
//            adapter = new VideoInfoAdapter(getActivity(), video_list, myCamera);
//            list_video_local.setAdapter(adapter);
//        }
//    }

    @Override
    public void onPause() {
        super.onPause();
        if (adapter != null) {
            adapter.unRegister();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (receiver != null) {
            getActivity().unregisterReceiver(receiver);
        }
    }

    private void loadData() {
        video_list.clear();
        localVideo();
        downloadVideo();

    }

    private void setListeners() {
        list_video_local.setOnItemClickListener(this);
        tv_edit.setOnClickListener(this);
        ll_anim.setOnClickListener(this);
        ll_category.setOnClickListener(this);
        ll_time.setOnClickListener(this);

    }

    private void downloadVideo() {
        if (myCamera != null) {
            File folder = new File(HiDataValue.getPathCameraVideoOnLineDownLoad(myCamera.getUid(),act));
            absolutePath = folder.getAbsolutePath();
            setImagesPath(absolutePath, 0);//0 是下载
        }
    }

    private void localVideo() {
        if (myCamera != null) {
            File folder = new File(HiDataValue.getPathCameraVideoLocalRecord(myCamera.getUid(),act));
            absolutePath = folder.getAbsolutePath();
            setImagesPath(absolutePath, 1); //1 是本地录制
        }
    }

    public final synchronized void setImagesPath(String path, int type) {
        File folder = new File(path);
        String[] imageFiles = folder.list();
        if (imageFiles != null && imageFiles.length > 0) {
            for (String imageFile : imageFiles) {
                if (imageFile.equals("SnapShot")) {
                    continue;
                }
                String abpath = path + "/" + imageFile;
                int fileLen = 0;
                File dF = new File(abpath);
                if (dF != null && dF.exists() && dF.isFile() && dF.length() <= 1024) {
                    dF.delete();
                    continue;
                }
                FileInputStream fis;
                try {
                    fis = new FileInputStream(dF);
                    fileLen = fis.available();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                long times = dF.lastModified();
                VideoInfo vi = new VideoInfo(type);
                vi.filename = imageFile;
                vi.start_time = coverStr(imageFile);
                vi.fileLen = fileLen;
                vi.setTime(times);
                video_list.add(vi);
            }
        }
    }

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private String coverStr(String str) {
        String string = str.split("\\.")[0];
        str = string.replace("_", "");
        try {
            Date date = new SimpleDateFormat("yyyyMMddHHmmss").parse(str);
            return sdf.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return "";
        }
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        VideoInfo videoInfo = video_list.get(position);
        if(adapter!=null&&adapter.mPlayLocal!=null){
            adapter.mPlayLocal.Stop2Mp4();
            adapter.mPlayLocal = null;
        }
        if (adapter != null && adapter.isDeleteMode()) {
            VideoInfoAdapter.ViewHolder holder = (VideoInfoAdapter.ViewHolder) view.getTag();
            holder.cb_check.setChecked(holder.cb_check.isChecked() ? false : true);
            if (holder.cb_check.isChecked()) {
                videoInfo.setChecked(true);
                delete_video_list.add(videoInfo);
            } else {
                delete_video_list.remove(videoInfo);
                videoInfo.setChecked(false);
            }
            return;
        }

        Bundle bundle = new Bundle();
        if (videoInfo.getType() == 0) {//下载
            absolutePath = HiDataValue.getPathCameraVideoOnLineDownLoad(myCamera.getUid(),act);
        } else {
            absolutePath = HiDataValue.getPathCameraVideoLocalRecord(myCamera.getUid(),act);
        }
        bundle.putString(FILE_PATH, absolutePath + "/" + videoInfo.filename);
        bundle.putString(HiDataValue.EXTRAS_KEY_UID, myCamera.getUid());
        bundle.putString("strat_time", videoInfo.start_time);
        Intent intent = new Intent();
        if (myCamera.isWallMounted) {
            intent.setClass(getActivity(), WallMountedPlayLocalActivity.class);
            intent.putExtras(bundle);
            startActivity(intent);
            return;
        }
        if (myCamera.isFishEye()) {
            // 初始化鱼眼顶装和壁装的模式
            int num = SharePreUtils.getInt("mInstallMode", getActivity(), myCamera.getUid());
            myCamera.mInstallMode = num == -1 ? 0 : num;
            intent.setClass(getActivity(), FishEyePlaybackLocalActivity.class);
        } else {
            intent.setClass(getActivity(), PlaybackLocalActivity.class);
        }
        intent.putExtras(bundle);
        startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_category://视频分类
                if (adapter.isDeleteMode()) {
                    handEdit();
                } else {
                    iv_category.animate().rotation(180f).setDuration(400).start();
                    showPuPVideo(tv_category);
                }
                break;
            case R.id.ll_time://文件大小，时长，时间，分类
                if (adapter.isDeleteMode()) {
                    handEdit();
                } else {
                    iv_time.animate().rotation(180f).setDuration(400).start();
                    showPuPSort(tv_time_sort);
                }
                break;
            case R.id.tv_edit://编辑
                handEdit();
                break;
            case R.id.ll_anim://删除
                if (delete_video_list.size() < 1) {
                    HiToast.showToast(getActivity(), getString(R.string.select_delect_video));
                    return;
                } else {
                    deleteVideoFile();
                }
                break;
        }
    }

    private void deleteVideoFile() {
        final NiftyDialogBuilder dialog = NiftyDialogBuilder.getInstance(getActivity());
        dialog.withButton1Text(getString(R.string.btn_no)).withButton2Text(getString(R.string.btn_yes)).withMessage(getString(R.string.confirm_video)).setButton1Click(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        }).setButton2Click(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                for (VideoInfo videoInfo : delete_video_list) {
                    absolutePath = videoInfo.getType() == 0 ? HiDataValue.getPathCameraVideoOnLineDownLoad(myCamera.getUid(),act) : HiDataValue.getPathCameraVideoLocalRecord(myCamera.getUid(),act);
                    File file = new File(absolutePath + "/" + videoInfo.filename);
                    if (videoInfo.getType() == 1) {
                        String str = HiDataValue.getPathCameraVideoLocalRecord(myCamera.getUid(),act) + "/SnapShot/" + videoInfo.filename;
                        File file1 = new File(str);
                        if (file1 != null && file1.exists()) {
                            file1.delete();
                        }
                    } else {
                        if (!TextUtils.isEmpty(videoInfo.getFilename())) {
                            String[] strings = videoInfo.getFilename().split("\\.");
                            if (strings.length > 0) {
                                String key = strings[0];
                                boolean remove = SharePreUtils.removeKey(HiDataValue.CACHE, getActivity(), key);
                            }
                        }
                    }
                    boolean deleted = file.delete();
                    video_list.remove(videoInfo);
                }
                adapter.setDeleteMode(false);
                adapter.notifyDataSetChanged();
                loadAnimation(HiTools.dip2px(getActivity(), 50));
                tv_edit.setText(getString(R.string.edit));
                if(video_list.size()<1){
                    ll_content.setVisibility(View.GONE);
                    rl_noting.setVisibility(View.VISIBLE);
                }
            }
        }).show();
    }

    private void handEdit() {
        delete_video_list.clear();
        for(VideoInfo info:video_list){
            info.setChecked(false);
        }
        if (adapter.isDeleteMode() == false) {//要删除了
            adapter.setDeleteMode(true);
            tv_edit.setText(getString(R.string.finish));
            adapter.notifyDataSetChanged();
            loadAnimation(HiTools.dip2px(getActivity(), -50));
        } else {// 关闭删除
            adapter.setDeleteMode(false);
            tv_edit.setText(getString(R.string.edit));
            adapter.notifyDataSetChanged();
            loadAnimation(HiTools.dip2px(getActivity(), 50));
        }
    }

    /**
     * 加载动画效果
     */
    private void loadAnimation(float values) {
        float curTranslationY = ll_anim.getTranslationY();
        ObjectAnimator animator = ObjectAnimator.ofFloat(ll_anim, "translationY", curTranslationY, values);
        animator.setDuration(250);
        animator.start();
    }


    private void showPuPSort(View v) {
        View customView = View.inflate(getContext(), R.layout.pup_local_video_sort, null);
        PopupWindow pw = new PopupWindow(getContext());
        pw.setContentView(customView);
        ColorDrawable cd = new ColorDrawable(-0000);
        pw.setBackgroundDrawable(cd);
        pw.setOutsideTouchable(true);
        pw.setFocusable(true);
        pw.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        pw.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        pw.showAsDropDown(v);

        TextView tv_time_drop = customView.findViewById(R.id.tv_time_drop);
        CheckBox cb_time_drop = customView.findViewById(R.id.cb_time_drop);
        TextView tv_time_rise = customView.findViewById(R.id.tv_time_rise);
        CheckBox cb_time_rise = customView.findViewById(R.id.cb_time_rise);
        TextView tv_file_size_drop = customView.findViewById(R.id.tv_file_size_drop);
        CheckBox cb_file_size_drop = customView.findViewById(R.id.cb_file_size_drop);
        TextView tv_file_size_rise = customView.findViewById(R.id.tv_file_size_rise);
        CheckBox cb_file_size_rise = customView.findViewById(R.id.cb_file_size_rise);

        RelativeLayout rl_time_drop=customView.findViewById(R.id.rl_time_drop);
        RelativeLayout rl_time_rise=customView.findViewById(R.id.rl_time_rise);
        RelativeLayout rl_file_size_drop=customView.findViewById(R.id.rl_file_size_drop);
        RelativeLayout rl_file_size_rise=customView.findViewById(R.id.rl_file_size_rise);

        if (mSelectMode_2 == 0) {
            cb_time_drop.setChecked(true);
            cb_time_rise.setChecked(false);
            cb_file_size_drop.setChecked(false);
            cb_file_size_rise.setChecked(false);
            tv_time_drop.setTextColor(getResources().getColor(R.color.color_theme_blue));
            tv_time_rise.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_file_size_drop.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_file_size_rise.setTextColor(getResources().getColor(R.color.txt_system_default));
        } else if (mSelectMode_2 == 1) {
            cb_time_drop.setChecked(false);
            cb_time_rise.setChecked(true);
            cb_file_size_drop.setChecked(false);
            cb_file_size_rise.setChecked(false);
            tv_time_drop.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_time_rise.setTextColor(getResources().getColor(R.color.color_theme_blue));
            tv_file_size_drop.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_file_size_rise.setTextColor(getResources().getColor(R.color.txt_system_default));
        } else if (mSelectMode_2 == 2) {
            cb_time_drop.setChecked(false);
            cb_time_rise.setChecked(false);
            cb_file_size_drop.setChecked(true);
            cb_file_size_rise.setChecked(false);
            tv_time_drop.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_time_rise.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_file_size_drop.setTextColor(getResources().getColor(R.color.color_theme_blue));
            tv_file_size_rise.setTextColor(getResources().getColor(R.color.txt_system_default));
        } else if (mSelectMode_2 == 3) {
            cb_time_drop.setChecked(false);
            cb_time_rise.setChecked(false);
            cb_file_size_drop.setChecked(false);
            cb_file_size_rise.setChecked(true);
            tv_time_drop.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_time_rise.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_file_size_drop.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_file_size_rise.setTextColor(getResources().getColor(R.color.color_theme_blue));
        }
        // 0: 时间降序
        rl_time_drop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pw.dismiss();
                mSelectMode_2 = 0;
                tv_time_sort.setText(getString(R.string.time_desc));
                Collections.sort(video_list, new TimeComparator());
                adapter.notifyDataSetChanged();
            }
        });
        //1：时间升序
        rl_time_rise.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pw.dismiss();
                mSelectMode_2 = 1;
                tv_time_sort.setText(getString(R.string.time_asce));
                Collections.sort(video_list, new TimeComparator());
                Collections.reverse(video_list);
                adapter.notifyDataSetChanged();
            }
        });
        //2:文件大小降序
        rl_file_size_drop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pw.dismiss();
                mSelectMode_2 = 2;
                tv_time_sort.setText(getString(R.string.file_size_desc));
                Collections.sort(video_list, new SizeComparator());
                Collections.reverse(video_list);
                adapter.notifyDataSetChanged();
            }
        });
        //3:文件大小升序
        rl_file_size_rise.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pw.dismiss();
                mSelectMode_2 = 3;
                tv_time_sort.setText(getString(R.string.file_size_asce));
                Collections.sort(video_list, new SizeComparator());
                adapter.notifyDataSetChanged();
            }
        });
        if (pw.isShowing()) {
            list_video_local.setBackgroundColor(Color.parseColor("#88999999"));
            list_video_local.setDivider(new ColorDrawable(Color.parseColor("#99bbbbbb")));
            list_video_local.setDividerHeight(HiTools.dip2px(getActivity(), 1));
        }
        pw.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                list_video_local.setBackgroundColor(Color.parseColor("#FFFFFF"));
                list_video_local.setDivider(new ColorDrawable(Color.parseColor("#F5F4F4")));
                list_video_local.setDividerHeight(HiTools.dip2px(getActivity(), 1));
                iv_time.animate().rotation(0f).setDuration(400).start();
            }
        });
    }

    @SuppressLint("Range")
    private void showPuPVideo(View v) {
        View customView = View.inflate(getContext(), R.layout.pup_local_video, null);
        PopupWindow pw = new PopupWindow(getContext());
        pw.setContentView(customView);
        ColorDrawable cd = new ColorDrawable(-0000);
        pw.setBackgroundDrawable(cd);
        pw.setOutsideTouchable(true);
        pw.setFocusable(true);
        pw.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        pw.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        TextView tv_all_video = customView.findViewById(R.id.tv_all_video);
        TextView tv_online_video = customView.findViewById(R.id.tv_online_video);
        TextView tv_local_video = customView.findViewById(R.id.tv_local_video);
        CheckBox cb_all = customView.findViewById(R.id.cb_all);
        CheckBox cb_local_record = customView.findViewById(R.id.cb_local_record);
        CheckBox cb_online_download = customView.findViewById(R.id.cb_online_download);
        RelativeLayout rl_all_video=customView.findViewById(R.id.rl_all_video);
        RelativeLayout rl_local_video=customView.findViewById(R.id.rl_local_video);
        RelativeLayout rl_online_video=customView.findViewById(R.id.rl_online_video);

        if (mSelectMode_1 == 0) {
            cb_all.setChecked(true);
            cb_local_record.setChecked(false);
            cb_online_download.setChecked(false);
            tv_all_video.setTextColor(getResources().getColor(R.color.color_theme_blue));
            tv_online_video.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_local_video.setTextColor(getResources().getColor(R.color.txt_system_default));
        } else if (mSelectMode_1 == 1) {
            cb_all.setChecked(false);
            cb_local_record.setChecked(true);
            cb_online_download.setChecked(false);
            tv_local_video.setTextColor(getResources().getColor(R.color.color_theme_blue));
            tv_all_video.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_online_video.setTextColor(getResources().getColor(R.color.txt_system_default));
        } else if (mSelectMode_1 == 2) {
            cb_all.setChecked(false);
            cb_local_record.setChecked(false);
            cb_online_download.setChecked(true);
            tv_online_video.setTextColor(getResources().getColor(R.color.color_theme_blue));
            tv_all_video.setTextColor(getResources().getColor(R.color.txt_system_default));
            tv_local_video.setTextColor(getResources().getColor(R.color.txt_system_default));
        }
        //所有本地视频
        rl_all_video.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSelectMode_1 = 0;
                pw.dismiss();
                tv_category.setText(getString(R.string.all));
                loadData();
                if (mSelectMode_2 == 0) {
                    Collections.sort(video_list, new TimeComparator());
                } else if (mSelectMode_2 == 1) {
                    Collections.sort(video_list, new SizeComparator());
                } else if (mSelectMode_2 == 2) {
                    Collections.sort(video_list, new SizeComparator());
                }
                adapter.notifyDataSetChanged();
            }
        });
        //本地录像
        rl_local_video.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSelectMode_1 = 1;
                pw.dismiss();
                tv_category.setText(getString(R.string.local_record));
                video_list.clear();
                localVideo();
                if (mSelectMode_2 == 0) {
                    Collections.sort(video_list, new TimeComparator());
                } else if (mSelectMode_2 == 1) {
                    Collections.sort(video_list, new SizeComparator());
                } else if (mSelectMode_2 == 2) {
                    Collections.sort(video_list, new SizeComparator());
                }
                adapter.notifyDataSetChanged();
            }
        });
        //远程下载
        rl_online_video.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mSelectMode_1 = 2;
                pw.dismiss();
                tv_category.setText(getString(R.string.remote_download));
                video_list.clear();
                downloadVideo();
                if (mSelectMode_2 == 0) {
                    Collections.sort(video_list, new TimeComparator());
                } else if (mSelectMode_2 == 1) {
                    Collections.sort(video_list, new SizeComparator());
                } else if (mSelectMode_2 == 2) {
                    Collections.sort(video_list, new SizeComparator());
                }
                adapter.notifyDataSetChanged();
            }
        });
        pw.showAsDropDown(v);
        if (pw.isShowing()) {
            list_video_local.setBackgroundColor(Color.parseColor("#88999999"));
            list_video_local.setDivider(new ColorDrawable(Color.parseColor("#99bbbbbb")));
            list_video_local.setDividerHeight(HiTools.dip2px(getActivity(), 1));
        }
        pw.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                list_video_local.setBackgroundColor(Color.parseColor("#FFFFFF"));
                list_video_local.setDivider(new ColorDrawable(Color.parseColor("#F5F4F4")));
                list_video_local.setDividerHeight(HiTools.dip2px(getActivity(), 1));
                iv_category.animate().rotation(0f).setDuration(400).start();
            }
        });
    }

}
